home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / gold / inst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.8 KB  |  113 lines

  1. /*
  2.  * The original copyright owners of the accompanying source code files have
  3.  * agreed to place such code into the public domain.  Accordingly, anyone
  4.  * who receives or obtains a copy of such source code is freely entitled to
  5.  * reproduce, use and otherwise exploit such code (including the right to
  6.  * make derivative works), at his/her own risk and expense, without any
  7.  * obligation or liability to the original copyright owners.
  8.  *
  9.  * We would appreciate (but do not require) that the following message be
  10.  * included in any derivative works:
  11.  *
  12.  * "Portions of this program were developed by Peter Broadwell, Rob Myers
  13.  * and Robin Schaufler while working in Silicon Valley."
  14.  *
  15.  * The accompanying source code files and related documentation materials
  16.  * are distributed on an "AS IS" basis, without any warranties or
  17.  * guarantees of any kind.  All implied warranties, including the implied
  18.  * warranties of merchantability and of fitness for any particular purpose,
  19.  * are expressly disclaimed.
  20.  */
  21. #include <stdio.h>
  22. #include "gl.h"        /* here for purposes of defining TRUE and FALSE only */
  23. #include "class.h"
  24. #include "classIds.h"
  25. #include "selectors.h"
  26.  
  27. extern int maldbug;
  28. extern char *gfmalloc();
  29. extern long fishPop;
  30.  
  31. #ifdef MALDEBUG
  32. #define Bzero(a,b)    { char *q=(a), *r=(b); \
  33.             if(maldbug) printf("bzeroing(0x%x,0x%x)\n",q,r); \
  34.             bzero(q,r);}
  35. #else
  36. #define Bzero(a,b)    bzero(a,b)
  37. #endif /* MALDEBUG */
  38.  
  39. fcnTable instFcns[] = {
  40.     EOTABLE
  41. };
  42.  
  43. class instClass = {
  44.     NULL,        /* super */
  45.     instFcns,        /* fcnTable */
  46.     sizeof(inst),    /* instSize */
  47.     INST        /* classId */
  48. };
  49.  
  50. inst instTemplate = {
  51.     &instClass,
  52.     0, 0
  53. };
  54.  
  55.  
  56.     /*
  57.      *  return TRUE if classId matches any classId up anInst's superclass chain
  58.      */
  59. isSuper(anInst, classId)
  60.     register inst *anInst;
  61.     register int classId;
  62. {
  63.     register class *aClass;
  64.  
  65.     if (anInst) {
  66.     for (aClass = anInst->myClass; aClass; aClass = aClass->super) {
  67.         if (aClass->classId == classId)
  68.         return TRUE;
  69.     }
  70.     }
  71.     return FALSE;
  72. }
  73.  
  74.     /* 
  75.      *  instantiate a new member of class aClass
  76.      */
  77.     inst *
  78. instantiate(aClass)
  79.     class *aClass;
  80. {
  81.     inst *anInst;
  82.  
  83.     if(! aClass)
  84.     return NULL;
  85.     if ((anInst = (inst *)gfmalloc(aClass->instSize)) == NULL) {
  86.     fprintf(stderr,"instantiate: gfmalloc for class %d returned NULL\n",
  87.         aClass->classId);
  88.     exit(-2);
  89.     }
  90.     Bzero(anInst, aClass->instSize);
  91.     return anInst;
  92. }
  93.  
  94.     /*
  95.      *  clone a new instance, using anInst as the template
  96.      */
  97.     inst *
  98. clone(anInst)
  99.     inst *anInst;
  100. {
  101.     inst *newInst;
  102.  
  103.     if(anInst == NULL)
  104.         return NULL;
  105.     if((newInst = instantiate(anInst->myClass)) == NULL)
  106.     return NULL;
  107.     Expand(anInst);
  108.     bcopy(anInst, newInst, anInst->myClass->instSize);
  109.     if(isSuper(newInst,GUPPY))
  110.         fishPop++;
  111.     return newInst;
  112. }
  113.